<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>设置客户端断开连接时是否中断脚本的执行</title>
 </head>
 <body class="docs"><div id="layout">
  <div id="layout-content"><div id="function.ignore-user-abort" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">ignore_user_abort</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">ignore_user_abort</span> &mdash; <span class="dc-title">设置客户端断开连接时是否中断脚本的执行</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.ignore-user-abort-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>ignore_user_abort</strong></span>
    ([ <span class="methodparam"><span class="type">bool</span> <code class="parameter">$value</code></span>
  ] ) : <span class="type">int</span></div>

  <p class="para rdfs-comment">
    设置客户端断开连接时是否中断脚本的执行
  </p>
  <p class="para">
   PHP 以命令行脚本执行时，当脚本终端结束，脚本不会被立即中止，除非设置 <code class="parameter">value</code> 为 <strong><code>TRUE</code></strong>，否则脚本输出任意字符时会被中止。</p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.ignore-user-abort-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<code class="parameter">value</code></dt>

     <dd>

      <p class="para">
       如果设置了该值，函数会把 <a href="misc.configuration.html#ini.ignore-user-abort" class="link">ignore_user_abort</a> ini 的值设置为 <code class="parameter">value</code>。
       如果未设置该值，函数不会改变设置，仅会返回之前的设置。
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.ignore-user-abort-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   以整型返回之前的设置
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.ignore-user-abort-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-4542">
    <p><strong>Example #1 <span class="function"><strong>ignore_user_abort()</strong></span>例子</strong></p>
    <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;Ignore&nbsp;user&nbsp;aborts&nbsp;and&nbsp;allow&nbsp;the&nbsp;script<br />//&nbsp;to&nbsp;run&nbsp;forever<br /></span><span style="color: #0000BB">ignore_user_abort</span><span style="color: #007700">(</span><span style="color: #0000BB">true</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">set_time_limit</span><span style="color: #007700">(</span><span style="color: #0000BB">0</span><span style="color: #007700">);<br /><br />echo&nbsp;</span><span style="color: #DD0000">'Testing&nbsp;connection&nbsp;handling&nbsp;in&nbsp;PHP'</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">//&nbsp;Run&nbsp;a&nbsp;pointless&nbsp;loop&nbsp;that&nbsp;sometime&nbsp;<br />//&nbsp;hopefully&nbsp;will&nbsp;make&nbsp;us&nbsp;click&nbsp;away&nbsp;from&nbsp;<br />//&nbsp;page&nbsp;or&nbsp;click&nbsp;the&nbsp;"Stop"&nbsp;button.<br /></span><span style="color: #007700">while(</span><span style="color: #0000BB">1</span><span style="color: #007700">)<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;Did&nbsp;the&nbsp;connection&nbsp;fail?<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">if(</span><span style="color: #0000BB">connection_status</span><span style="color: #007700">()&nbsp;!=&nbsp;</span><span style="color: #0000BB">CONNECTION_NORMAL</span><span style="color: #007700">)<br />&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;Sleep&nbsp;for&nbsp;10&nbsp;seconds<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">sleep</span><span style="color: #007700">(</span><span style="color: #0000BB">10</span><span style="color: #007700">);<br />}<br /><br /></span><span style="color: #FF8000">//&nbsp;If&nbsp;this&nbsp;is&nbsp;reached,&nbsp;then&nbsp;the&nbsp;'break'&nbsp;<br />//&nbsp;was&nbsp;triggered&nbsp;from&nbsp;inside&nbsp;the&nbsp;while&nbsp;loop<br /><br />//&nbsp;So&nbsp;here&nbsp;we&nbsp;can&nbsp;log,&nbsp;or&nbsp;perform&nbsp;any&nbsp;other&nbsp;tasks<br />//&nbsp;we&nbsp;need&nbsp;without&nbsp;actually&nbsp;being&nbsp;dependent&nbsp;on&nbsp;the&nbsp;<br />//&nbsp;browser.<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.ignore-user-abort-notes">
  <h3 class="title">注释</h3>
  <p class="para">
   在PHP尝试发送信息到客户端之前，不会检测到用户是否已中断连接。
   仅使用 echo 语句不能确保信息已发送，参见 <span class="function"><a href="flush.html" class="function">flush()</a></span> 函数。 
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.ignore-user-abort-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="connection_aborted.html" class="function" rel="rdfs-seeAlso">connection_aborted()</a> - 检查客户端是否已经断开</span></li>
    <li class="member"><span class="function"><a href="connection_status.html" class="function" rel="rdfs-seeAlso">connection_status()</a> - 返回连接的状态位</span></li>
    <li class="member">
     <a href="features.connection_handling.html" class="link">Connection Handling</a>
     关于PHP连接处理的完整描述。
    </li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>